#include<iostream>
using namespace std;

int main()
{
    char c;
    int i,n;
    cin >> c >> n;
    if(c == 'w')
    {
    	i = 7;
	}
	else
	{
		i = c-'0'; 
	}
	i =(i+n)%7;
	if(i==0)
	{
		cout << 7;
	}
	else 
	{
		cout << i ;
	}
	
	return 0;
}
